public class TreeCreateString extends BinaryTree{
    public String Treestr(TreeNode root) {
        StringBuilder sbu = new StringBuilder();
        treestrChild(root,sbu);
        return sbu.toString();
    }
    public void treestrChild(TreeNode root,StringBuilder sbu) {
        if(root == null) {
            return;
        }
        sbu.append(root.val);
        //1.先递归左树
        if(root.left != null){
            sbu.append("(");
            treestrChild(root.left,sbu);
            sbu.append(")");
        }else{
            if(root.right == null) {
                return;
            }else {
                sbu.append(")");
            }
        }
        //2.递归右树
        if(root.right != null) {
            sbu.append("(");
            treestrChild(root.right,sbu);
        }else{
            return;
        }
    }
}
